package com.java110.mall.cart.bmo.storeOrderUp.impl;


import com.java110.mall.cart.bmo.storeOrderUp.IGetStoreOrderUpBMO;
import com.java110.dto.vipUser.ShopVipUserDto;
import com.java110.intf.cart.IStoreOrderUpInnerServiceSMO;
import com.java110.intf.shop.IShopVipUserInnerServiceSMO;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.java110.dto.storeOrder.StoreOrderUpDto;


import java.util.ArrayList;
import java.util.List;

@Service("getStoreOrderUpBMOImpl")
public class GetStoreOrderUpBMOImpl implements IGetStoreOrderUpBMO {

    @Autowired
    private IStoreOrderUpInnerServiceSMO storeOrderUpInnerServiceSMOImpl;
    @Autowired
    private IShopVipUserInnerServiceSMO shopVipUserInnerServiceSMOImpl;
    /**
     *
     *
     * @param  storeOrderUpDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(StoreOrderUpDto storeOrderUpDto) {


        int count = storeOrderUpInnerServiceSMOImpl.queryStoreOrderUpsCount(storeOrderUpDto);

        List<StoreOrderUpDto> storeOrderUpDtos = null;
        if (count > 0) {
            storeOrderUpDtos = storeOrderUpInnerServiceSMOImpl.queryStoreOrderUps(storeOrderUpDto);
            for(StoreOrderUpDto storeOrderUpD : storeOrderUpDtos){
                if(!StringUtil.isNullOrNone( storeOrderUpD.getVipId() )){
                    ShopVipUserDto shopVipUserDto = new ShopVipUserDto();
                    shopVipUserDto.setVipId( storeOrderUpD.getVipId() );
                    List<ShopVipUserDto> ShopVipUserDtos = shopVipUserInnerServiceSMOImpl.queryShopVipUsers( shopVipUserDto );
                    if(null != ShopVipUserDtos && ShopVipUserDtos.size() > 0){
                        storeOrderUpD.setShopVipUserDto( ShopVipUserDtos.get( 0 ) );
                    }
                }
            }

        } else {
            storeOrderUpDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) storeOrderUpDto.getRow()), count, storeOrderUpDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
